<?php

namespace App\Repositories;

use App\Models\DriverFinancial;
use BobCoder\Construct\Foundation\Repository\Repository;


class DriverFinancialRepository extends Repository
{
    protected $model;

    public function __construct()
    {
        $this->model = new DriverFinancial();
    }


    /**
     *
     *
     * 流水列表
     * @param int $companyId 公司ID
     * @param int $pageSize
     * @return mixed
     * @Author 姿势就是力量
     */
    public function getPageList(int $companyId, int $pageSize = 10)
    {
        return $this->model->company($companyId)
            ->with([
                'driver:id,real_name,phone',
                'user:id,phone',
                'service:id,name',
                'car:id,number'
            ])
            ->orderBy('created_at', 'desc')
            ->paginate($pageSize)
            ->toArray();
    }


    /**
     * 统计流水金额
     * @param int $companyId 公司ID
     * @return mixed
     * @Author 姿势就是力量
     */
    public function totalMoney(int $companyId)
    {
        return $this->model->company($companyId)->sum('money');
    }

}
